home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Dev / Mui / Mcc_speedbar.lha / MCC_SpeedBar / Developer / C / Examples / demo5.c < prev    next >
C/C++ Source or Header  |  2002-12-21  |  7KB  |  207 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/datatypes.h>
  5. #include <proto/muimaster.h>
  6. #include <clib/alib_protos.h>
  7. #include <mui/SpeedBar_mcc.h>
  8. #include <mui/SpeedButton_mcc.h>
  9. #include <mui/SpeedBarCfg_mcc.h>
  10. #include <datatypes/pictureclass.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13.  
  14. /***********************************************************************/
  15.  
  16. long __stack = 8192;
  17. struct Library *DataTypesBase;
  18. struct Library *MUIMasterBase;
  19.  
  20. /***********************************************************************/
  21.  
  22. #ifndef MAKE_ID
  23. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  24. #endif
  25.  
  26. /***********************************************************************/
  27.  
  28. struct MUIS_SpeedBar_Button buttons[] =
  29. {
  30.     {0, "_Get", "Get the disc.", 0, NULL},
  31.     {1, "Sa_ve", "Save the disc.", 0, NULL},
  32.     {2, "_Stop", "Stop the connection.", 0, NULL},
  33.     {MUIV_SpeedBar_Spacer},
  34.     {3, "_Disc", "Disc page.", 0, NULL},
  35.     {4, "_Matches", "Matches page.", 0, NULL},
  36.     {5, "_Edit", "Edit page.", 0, NULL},
  37.     {MUIV_SpeedBar_End},
  38. };
  39.  
  40. STRPTR pics[] =
  41. {
  42.     "PROGDIR:Pics/Get",
  43.     "PROGDIR:Pics/Save",
  44.     "PROGDIR:Pics/Stop",
  45.     "PROGDIR:Pics/Disc",
  46.     "PROGDIR:Pics/Matches",
  47.     "PROGDIR:Pics/Edit",
  48.     NULL
  49. };
  50.  
  51. /***********************************************************************/
  52.  
  53. static Object *
  54. loadDTBrush(struct MyBrush *brush,STRPTR file)
  55. {
  56.     struct BitMapHeader *bmh;
  57.     register Object     *dto;
  58.  
  59.     if (!(dto = NewDTObject(file,DTA_GroupID,GID_PICTURE,PDTA_Remap,FALSE,PDTA_DestMode,PMODE_V42,TAG_DONE)) ||
  60.         !(DoMethod(dto,DTM_PROCLAYOUT,NULL,1)) ||
  61.         !(GetDTAttrs(dto,PDTA_DestBitMap,&brush->BitMap,PDTA_CRegs,&brush->Colors,PDTA_BitMapHeader,&bmh,TAG_DONE)==3))
  62.     {
  63.         if (dto)
  64.         {
  65.             DisposeDTObject(dto);
  66.             dto = NULL;
  67.         }
  68.     }
  69.     else
  70.     {
  71.         brush->Width  = bmh->bmh_Width;
  72.         brush->Height = bmh->bmh_Height;
  73.     }
  74.  
  75.     return dto;
  76. }
  77.  
  78. /***********************************************************************/
  79.  
  80. #define TEMPLATE "STRIP,NUMBUTTON/N"
  81.  
  82. int
  83. main(int argc,char **argv)
  84. {
  85.     int res;
  86.  
  87.     if (DataTypesBase = OpenLibrary("datatypes.library",37))
  88.     {
  89.         if (MUIMasterBase = OpenLibrary("muimaster.library",19))
  90.         {
  91.             struct MyBrush                  brushes[sizeof(pics)/sizeof(STRPTR)-1], *b[sizeof(pics)/sizeof(STRPTR)-1];
  92.             struct MUIS_SpeedBarCfg_Config  c = {MUIV_SpeedBar_ViewMode_TextGfx, MUIV_SpeedBarCfg_Borderless|MUIV_SpeedBarCfg_Sunny};
  93.             Object                          *dtos[sizeof(pics)/sizeof(STRPTR)-1], *app, *win, *sb;
  94.             Object                          *cfg, *update;
  95.             int                             i;
  96.  
  97.             for (i = 0; pics[i]; i++)
  98.             {
  99.                 if (!(dtos[i] = loadDTBrush(brushes+i,pics[i])))
  100.                 {
  101.                     b[i] = NULL;
  102.                     printf("%s: warning can't load %s\n",argv[0],pics[i]);
  103.                 }
  104.                 else b[i] = brushes+i;
  105.             }
  106.  
  107.             if (app = ApplicationObject,
  108.                     MUIA_Application_Title,         "SpeedBar Demo5",
  109.                     MUIA_Application_Version,       "$VER: SpeedBarDemo5 16.1 (3.12.2002)",
  110.                     MUIA_Application_Copyright,     "Copyright 1999-2002 by Alfonso Ranieri",
  111.                     MUIA_Application_Author,        "Alfonso Ranieri <alforan@tin.it>",
  112.                     MUIA_Application_Description,   "Speed(Bar|Button|BarCfg).mcc test",
  113.                     MUIA_Application_Base,          "SPEEDBARTEST",
  114.                     SubWindow, win = WindowObject,
  115.                         MUIA_Window_ID,             MAKE_ID('M','A','I','N'),
  116.                         MUIA_Window_Title,          "SpeedBar Demo5",
  117.                         WindowContents, VGroup,
  118.                             Child, sb = SpeedBarObject,
  119.                                 GroupFrame,
  120.                                 MUIA_Group_Horiz,               TRUE,
  121.                                 MUIA_SpeedBar_Layout,           MUIV_SpeedBar_Layout_Left,
  122.                                 MUIA_SpeedBar_Borderless,       TRUE,
  123.                                 MUIA_SpeedBar_Sunny,            TRUE,
  124.                                 MUIA_SpeedBar_Buttons,          buttons,
  125.                                 MUIA_SpeedBar_StripUnderscore,  TRUE,
  126.                                 MUIA_SpeedBar_EnableUnderscore, TRUE,
  127.                                 MUIA_SpeedBar_BarSpacer,        TRUE,
  128.                                 MUIA_SpeedBar_Images,           b,
  129.                             End,
  130.                             Child, VSpace(0),
  131.                             Child, VGroup,
  132.                                 GroupFrameT("Appareance"),
  133.                                 Child, cfg = SpeedBarCfgObject,
  134.                                     MUIA_SpeedBarCfg_Config, &c,
  135.                                 End,
  136.                                 Child, VSpace(0),
  137.                                 Child, update = MUI_MakeObject(MUIO_Button,"_Update"),
  138.                             End,
  139.                             Child, VSpace(0),
  140.                         End,
  141.                     End,
  142.                 End)
  143.             {
  144.                 ULONG sigs = 0, id;
  145.  
  146.                 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  147.                 DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,TAG_USER);
  148.  
  149.                 set(win,MUIA_Window_Open,TRUE);
  150.  
  151.                 while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs))!=MUIV_Application_ReturnID_Quit)
  152.                 {
  153.                     if (id==TAG_USER)
  154.                     {
  155.                         struct MUIS_SpeedBarCfg_Config *c;
  156.  
  157.                         get(cfg,MUIA_SpeedBarCfg_Config,&c);
  158.  
  159.                         SetAttrs(sb,MUIA_SpeedBar_ViewMode,c->ViewMode,
  160.                                     MUIA_SpeedBar_Borderless,c->Flags & MUIV_SpeedBarCfg_Borderless,
  161.                                     MUIA_SpeedBar_RaisingFrame,c->Flags & MUIV_SpeedBarCfg_Raising,
  162.                                     MUIA_SpeedBar_SmallImages,c->Flags & MUIV_SpeedBarCfg_SmallButtons,
  163.                                     MUIA_SpeedBar_Sunny,c->Flags & MUIV_SpeedBarCfg_Sunny,
  164.                                     TAG_DONE);
  165.                     }
  166.  
  167.                     if (sigs)
  168.                     {
  169.                         sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  170.                         if (sigs & SIGBREAKF_CTRL_C) break;
  171.                     }
  172.                 }
  173.  
  174.                 MUI_DisposeObject(app);
  175.  
  176.                 res = RETURN_OK;
  177.             }
  178.             else
  179.             {
  180.                 printf("%s: can't create application\n",argv[0]);
  181.                 res = RETURN_FAIL;
  182.             }
  183.  
  184.             for (i = 0; pics[i]; i++)
  185.                 if (dtos[i]) DisposeDTObject(dtos[i]);
  186.  
  187.             CloseLibrary(MUIMasterBase);
  188.         }
  189.         else
  190.         {
  191.             printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
  192.             res = RETURN_ERROR;
  193.         }
  194.  
  195.         CloseLibrary(DataTypesBase);
  196.     }
  197.     else
  198.     {
  199.         printf("%s: can't open datatypes.library ver 37 or higher\n",argv[0]);
  200.         res = RETURN_ERROR;
  201.     }
  202.  
  203.     return res;
  204. }
  205.  
  206. /***********************************************************************/
  207.